package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.LklMerchant;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 拉卡拉商户号表 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-12-25
 */
public interface LklMerchantMapper extends BaseMapper<LklMerchant> {

    @Select({"<script>",
            "SELECT ",
            "o.`name` AS schoolName,",
            "s.merchant_name,",
            "s.merchant_no,",
            " m.*",
            "from",
            "lkl_merchant m",
            "LEFT JOIN organization o ON o.id = m.school_id",
            "JOIN lkl_merchant_set s ON s.id = m.merchant_set_id",
            "where",
            "1=1",
            "<if test ='yearPart != null and yearPart !=&apos;&apos;'>",
            "AND m.year_part = #{yearPart} ",
            "</if>",
            "<if test ='quarterNum != null and quarterNum !=&apos;&apos;'>",
            "AND m.quarter_num = #{quarterNum} ",
            "</if>",
            "ORDER BY m.created_at DESC",
            "</script>"})
    public List<LklMerchant> getLklMerchantList(@Param("yearPart") String yearPart,@Param("quarterNum") String quarterNum);



    @Select({"<script>",
            "SELECT",
            "t1.*,",
//            "t2.teacher_id,",
            "t3.name AS merchantName",
            "FROM",
            "lkl_merchant AS t1",
            "LEFT JOIN lkl_merchant_set AS t2 ON t1.merchant_set_id = t2.id",
            "LEFT JOIN staff AS t3 ON t2.teacher_id = t3.id",
            "WHERE",
            "t1.school_id = #{schoolId}",
            "AND t1.pid &lt;&gt; 0",
            "</script>"})
    public List<LklMerchant> getMerchantNameBySchoolId(@Param("schoolId") String schoolId);

}
